package org.come.Jpanel;

import com.tool.btn.ChooseLhBtn;
import com.tool.btn.DepositBtn;
import com.tool.btn.FormsOnOffBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.apache.commons.lang.StringUtils;
import org.come.bean.LoginResult;
import org.come.mouslisten.PetDepositJlistChoseMouslisten;
import org.come.until.CutButtonImage;
import org.come.until.SrcollPanelUI;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class ChooseLiangHaoTypeJpanel extends JPanel {

    private JScrollPane jScrollPane;
    private JList<Integer> listLh;
    private DefaultListModel<Integer> listModel;
    private ChooseLhBtn btntop,// 向上图标
            btnbottom,// 向下图标
            btntopset,// 置顶图标
            btnbottomset,lhBtn;//确定
    public ChooseLiangHaoTypeJpanel() {
        if (MyIsif.getStyle().equals("水墨UI")) {
            this.setPreferredSize(new Dimension(293, 409));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 638);
            offBtn.setBounds(256, 11, 25, 25);
            this.add(offBtn);

            listModel = new DefaultListModel<Integer>();
            listLh = new JList<Integer>() {
                {
                    setOpaque(false);
                }
            };
            listLh.setSelectionBackground(new Color(0, 0, 0, 0));
            listLh.setFont(new Font("微软雅黑", 1, 14));
            listLh.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listLh.setSelectionForeground(Color.white);
            listLh.setForeground(Color.white);
            listLh.setModel(listModel);

            jScrollPane = new JScrollPane(listLh);
            jScrollPane.setVerticalScrollBarPolicy(22);
            jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            jScrollPane.getViewport().setOpaque(false);
            jScrollPane.setOpaque(false);
            jScrollPane.setBounds(55, 45, 194, 320);
            jScrollPane.setBorder(BorderFactory.createLineBorder(new Color(31, 7, 8)));
            jScrollPane.setBorder(BorderFactory.createEmptyBorder());
            jScrollPane.setHorizontalScrollBarPolicy(31);
            this.add(jScrollPane);

            btnbottomset = new ChooseLhBtn("inkImg/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "确定", 2, this);
            this.btnbottomset.setBounds(118, 370, 59, 24);
            this.add(this.btnbottomset);

            lhBtn = new ChooseLhBtn("inkImg/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "炼化", 3, this);
            this.lhBtn.setBounds(50, 370, 59, 24);
            this.add(this.lhBtn);
        } else {
            this.setPreferredSize(new Dimension(290, 408));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/s74.png", 1, 638);
            offBtn.setBounds(268, 0, 25, 25);
            this.add(offBtn);

            listModel = new DefaultListModel<Integer>();
            listLh = new JList<Integer>() {
                {
                    setOpaque(false);
                }
            };
            listLh.setSelectionBackground(new Color(0, 0, 0, 0));
            listLh.setFont(new Font("微软雅黑", 1, 14));
            listLh.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listLh.setSelectionForeground(Color.white);
            listLh.setForeground(Color.white);
            listLh.setModel(listModel);

            jScrollPane = new JScrollPane(listLh);
            jScrollPane.setVerticalScrollBarPolicy(22);
            jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            jScrollPane.getViewport().setOpaque(false);
            jScrollPane.setOpaque(false);
            jScrollPane.setBounds(45, 58, 180, 260);
            jScrollPane.setBorder(BorderFactory.createLineBorder(new Color(31, 7, 8)));
            jScrollPane.setBorder(BorderFactory.createEmptyBorder());
            jScrollPane.setHorizontalScrollBarPolicy(31);
            this.add(jScrollPane);

            btnbottomset = new ChooseLhBtn("inkImg/hongmu/6026.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "确定", 2, this);
            this.btnbottomset.setBounds(118, 350, 60, 25);
            this.add(this.btnbottomset);

            lhBtn = new ChooseLhBtn("inkImg/hongmu/6026.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "炼化", 3, this);
            this.lhBtn.setBounds(50, 350, 60, 25);
            this.add(this.lhBtn);
        }
    }
    private ImageIcon icon;

    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (MyIsif.getStyle().equals("水墨UI")) {
            if (icon == null)
                icon = new ImageIcon("inkImg/newbackground/lianghao.png");
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 293, 409, this);

            final LoginResult login = RoleData.getRoleData().getLoginResult();
            String num = login.getLiangHao();
            Integer type = login.getLianghaotype() == null ? 0 : login.getLianghaotype();
            if (StringUtils.isNotEmpty(num)) {
                String[] nums = num.split("");
                for (int i = 0; i < listLh.getModel().getSize(); i++) {
                    for (int j = 0; j < nums.length; j++) {
                        int xnum = 70 + (20 * j);
                        int ynum = 48 + (21 * i);
                        g.drawImage(CutButtonImage.getImage("inkImg/number/" + String.valueOf(i) + nums[j] + ".png", 11, 15).getImage(), xnum, ynum, 11, 15, this);
                    }
                }
            }
        } else {
            if (icon == null)
                icon = new ImageIcon("inkImg/hongmu/lianghaoh.png");
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 290, 408, this);

            final LoginResult login = RoleData.getRoleData().getLoginResult();
            String num = login.getLiangHao();
            Integer type = login.getLianghaotype() == null ? 0 : login.getLianghaotype();
            if (StringUtils.isNotEmpty(num)) {
                String[] nums = num.split("");
                for (int i = 0; i < listLh.getModel().getSize(); i++) {
                    for (int j = 0; j < nums.length; j++) {
                        int xnum = 70 + (20 * j);
                        int ynum = 60 + (21 * i);
                        g.drawImage(CutButtonImage.getImage("inkImg/number/" + String.valueOf(i) + nums[j] + ".png", 11, 15).getImage(), xnum, ynum, 11, 15, this);
                    }
                }
            }
        }
    }
    // 初始列表
    public void init(List<Integer> list) {
        listModel.clear();
        for (int i = 0; i < list.size(); i++) {
            listModel.addElement(list.get(i));
        }
    }

    public JList<Integer> getListLh() {
        return listLh;
    }

    public void setListLh(JList<Integer> listLh) {
        this.listLh = listLh;
    }

    public DefaultListModel<Integer> getListModel() {
        return listModel;
    }

    public void setListModel(DefaultListModel<Integer> listModel) {
        this.listModel = listModel;
    }
}
